package com.menfan.saas.service.impl;

import com.menfan.saas.dao.UserMapper;
import com.menfan.saas.domain.UserEntity;
import com.menfan.saas.model.User;
import com.menfan.saas.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/30 0030.
 */
@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    public User getUserInfo(Integer id) {
        UserEntity userEntity = userMapper.getUserInfo(id);
        User user = new User();
        BeanUtils.copyProperties(userEntity, user);
        return user;
    }

    public List<User> getUserList() {
        List<UserEntity> userEntityList = userMapper.getUserList();
        List<User> userList = new ArrayList<User>();
        for (UserEntity userEntity : userEntityList) {
            User user = new User();
            BeanUtils.copyProperties(userEntity, user);
            userList.add(user);
        }
        return userList;
    }

    @Transactional("localTransactionManager")
    public void addUserInfo(String name) {
        UserEntity userEntity=new UserEntity();
        userEntity.setUsername(name);
        userEntity.setPassword("1234");
        userMapper.addUser(userEntity);
    }
}
